package sketch.generator;

import sketch.util.Checker;

/**
 * The abstract classes with two children. It is designed
 * as a recursive construct
 * */
public abstract class BinaryLink implements IIterationLink {

	private IIterationLink left;
	private IIterationLink right;
	
	public BinaryLink() {}
	
	public BinaryLink(IIterationLink left, IIterationLink right) {
		Checker.checkNull(left, "The left iteration link could not be null!");
		Checker.checkNull(right, "the right iteration link could not be null!");
		this.left = left;
		this.right = right;
	}
	
	public BinaryLink(IGenerator<?> left, IGenerator<?> right) {
		this(new GeneratorLink(left), new GeneratorLink(right));
	}
	
	public IIterationLink getLeft() {
		return this.left;
	}
	
	public void setLeft(IIterationLink left) {
		this.left = left;
	}
	
	public IIterationLink getRight() {
		return this.right;
	}
	
	public void setRight(IIterationLink right) {
		this.right = right;
	}
	
	/**
	 * All inherited methods
	 * */
	public void reset() {
		this.left.reset();
		this.right.reset();
	}
	
	public abstract boolean hasNext();
	
	public abstract void next();
	
	public abstract BinaryLink createNewInstance(IIterationLink left, IIterationLink right);
}
